
#include <stdio.h>
#include <event2/event.h>


int fdex()
{
	SOCKET sock;
	struct sockaddr_in addr;

	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = inet_addr("127.0.0.1");
	addr.sin_port = htons(8000);

	sock = socket(AF_INET, SOCK_DGRAM, 0);
	bind(sock, (struct sockaddr *)&addr, sizeof(addr));
	return sock;
}


void hook(int sock, short evnt, void *arg)
{
	printf("%d get event %d\n", sock, evnt);
}


int main()
{
	const char **methods;
	struct event_base *base;
	struct event_config *cfg;
	struct event *evnt;
	int ret;

	WSADATA wsaData;
	WSAStartup(MAKEWORD(2, 0), &wsaData);

	event_enable_debug_mode();
	methods = event_get_supported_methods();

	cfg = event_config_new();
	event_config_require_features(cfg, EV_FEATURE_O1|EV_FEATURE_FDS);
	event_config_set_flag(cfg, EVENT_BASE_FLAG_STARTUP_IOCP);
	
	base = event_base_new();

    evnt = event_new(base, fdex(), EV_READ, hook, NULL);
	event_add(evnt, NULL);

	ret = event_base_dispatch(base);

	while (1)
		Sleep(100);

	event_free(evnt);
	event_base_free(base);
	event_config_free(cfg);
	return 0;
}

